package controller

import (
	"github.com/gin-gonic/gin"
	"myserver/model"
	"myserver/response"
	"myserver/tool"
)

type TitleController struct {
}

func (c *TitleController) Router(apiGroup *gin.RouterGroup) {
	apiGroup.GET("/menus", c.getMenus)
}

func (c *TitleController) getMenus(context *gin.Context) {
	db := tool.MyDb
	var titles []model.OneTitle
	res := db.Db.Preload("TwoTitle").Find(&titles)
	if res.RowsAffected != 0 {
		response.Success(context, response.Ok().AddData("titles", titles))
	} else {
		response.Failed(context, response.Error())
	}
}
